package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.Product;
import com.ysd.util.DBManager;

public class ChanPinSoSuoDaolmpl {
	public List<Product> getProductList(String name){
		List<Product> List = new ArrayList<Product>();
		Connection conn = DBManager.getConnection();
		 Statement st = null;
		 ResultSet rs = null;
		 
		 try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from product where productName like '%"+name+"%'");
			while(rs.next()){
				int pId = rs.getInt("productId");
				String pName = rs.getString("productName");
				String imgs = rs.getString("imgs");
				Product product = new Product(pId, pName, imgs);
				List.add(product);
			}
			return List;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
}
